
$(function(){
    var yhzhkmdmys = {
        grid:$("#yhzhkmdmys_grid"),
        gridOptions:{
            url:$.webPath() + "/cwgl/kmys/yhzhkmdmys/yhzhkmdmysList",
//            updateUrl:$.webPath() +'/cwgl/kmys/yhzhkmdmys/save',
            toolbar:'#toolbar_yhzhkmdmys',
            fitColumns:true,
            fit:true,
            rownumbers:true,
            pageNumber: 1,
            pagination:true,
            singleSelect:true,
            columns:[
                [
                    {field:'nbgsJc',title:'公司名称',width:100},
                    {field:'khh.qc',title:'开户行',width:100},
                    {field:'khh.zh',title:'银行账号',width:100},
                    {field:'khh.kmdm',title:"科目代码",editor:{type:'text'},width:100},
                    {field:'khh.gysfzhsdm',title:"供应商辅助核算代码",editor:{type:'text'},width:100},
                    {field:'khh.khfzhsdm',title:"客户辅助核算代码",editor:{type:'text'},width:100},
                    {field:'cz',title:'操作',formatter:function(value,row,index){
                        if(value && value == 'save')
                            return '<a index="'+index+'" name="save" href="javascript:void(0)" onclick="save_yhzhkmdmys('+index+')"></a>'
                        return '<a index="'+index+'" name="edit" href="javascript:void(0)" onclick="edit_yhzhkmdmys('+index+')"></a>'
                    },width:30,align:'center'}
                ]
            ],
            onLoadSuccess:function(){
                $("a[name='edit']").linkbutton({
                    plain:true,
                    iconCls:'icon-edit'
                });
                $("a[name='save']").linkbutton({
                    plain:true,
                    iconCls:'icon-save'
                });
            },
            onBeforeEdit:function(rowIndex, rowData){
                yhzhkmdmys.grid.edatagrid("updateRow",{
                    index: rowIndex,
                    row:$.extend({},rowData,{cz:'save'})

                });
                $("a[name='save']").linkbutton({
                    plain:true,
                    iconCls:'icon-save'
                });
            },
            onAfterEdit: function (index, row) {
                var url = $.webPath() +'/cwgl/kmys/yhzhkmdmys/save_yhzhkmdmys';
                $.post(url, row, function (data) {
                    if(data.statusCode == 200){
                        yhzhkmdmys.grid.datagrid('updateRow', {
                            index: index,
                            row:$.extend({},row,{cz:'edit'})
                        });
                        $("a[name='edit']").linkbutton({
                            plain:true,
                            iconCls:'icon-edit'
                        });
                    } else {
                        $.messager.alert('info',data.message);
                        yhzhkmdmys.grid.edatagrid("beginEdit",index);
                    }
                }, 'json');
            }
        },
//        save:function(){},
        search:function(){
            yhzhkmdmys.grid.datagrid("load",{
                nbgsId:$("#yhzhkmdmys_nbgs").combobox("getValue") || ''
//                mc:$("#yhzhkmdmys_mc").val() || ''
//                kmdm:$("#yhzhkmdmys_kmdm").val() || ''
            });
        }
    }
    yhzhkmdmys.grid.edatagrid(yhzhkmdmys.gridOptions);
    $("#yhzhkmdmys_nbgs").gsjgtree(1);
//    $("#yhzhkmdmys_qyjg").qyjgcombobox(false);
    $("#btn_yhzhkmdmys_search").click(function(){
        yhzhkmdmys.search();
    });
});
function save_yhzhkmdmys(index){
    $("#yhzhkmdmys_grid").edatagrid("endEdit",index);
}
function edit_yhzhkmdmys(index){
    $("#yhzhkmdmys_grid").edatagrid("beginEdit",index);
}